<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 11] FileWriter</TITLE>
<META NAME="author" CONTENT="Mark Grand and Jonathan Knudsen">
<META NAME="date" CONTENT="Fri Aug  8 16:36:58 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java Fundamental Classes Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Fundamental Classes Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch11_22.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 11<br>The java.io Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch11_24.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>FileWriter</H1>

<H2>Name</H2>

FileWriter

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch11-REFSECT1-AUTOID.154">Synopsis</A></h2>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Class Name:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.io.FileWriter</tt>

<p>
<DT CLASS=varlistentry>Superclass:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.io.OutputStreamWriter</tt>

<p>
<DT CLASS=varlistentry>Immediate Subclasses:<br>
<DD>

<P CLASS=para>
None

<p>
<DT CLASS=varlistentry>Interfaces Implemented:<br>
<DD>

<P CLASS=para>
None

<p>
<DT CLASS=varlistentry>Availability:<br>
<DD>

<P CLASS=para>
New as of JDK 1.1</DL>
</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch11-REFSECT1-AUTOID.155">Description</A></h2>

<P CLASS=para>
The <tt CLASS=literal>FileWriter</tt> class represents 
a character stream that writes data to a file. It is a subclass of <tt CLASS=literal>OutputStreamWriter</tt> 
that uses a default buffer size (8192 bytes) to write bytes to a file and 
the default character encoding scheme to convert characters to bytes. If 
you need to specify the character 
encoding or the buffer size, wrap an <tt CLASS=literal>OutputStreamWriter</tt> 
around a <tt CLASS=literal>FileOutputStream</tt>. 

<P CLASS=para>
The file can be specified using a <tt CLASS=literal>FileDescriptor</tt>, 
a <tt CLASS=literal>File</tt> object, or a <tt CLASS=literal>String</tt> 
that represents a pathname. All of the constructors can throw a <tt CLASS=literal>SecurityException</tt> 
if the application does not have permission to write to the specified file. 

<P CLASS=para>
<tt CLASS=literal>FileWriter</tt> provides a low-level 
interface for writing character data to a file. You should think about 
wrapping a <tt CLASS=literal>FileWriter</tt> with 
a <tt CLASS=literal>BufferedWriter</tt> to increase 
writing efficiency. 

<P CLASS=para>
If you need to write binary data to a file, you should use a <tt CLASS=literal>FileOutputStream</tt> 
wrapped by a <tt CLASS=literal>DataOutputStream</tt> 
or a <tt CLASS=literal>PrintStream</tt> instead. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch11-REFSECT1-AUTOID.156">Class Summary</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public class java.io.FileWriter extends java.io.OutputStreamWriter {
  // Constructors
  public FileWriter(String fileName);
  public FileWriter(String fileName, boolean append);
  public FileWriter(File file);
  public FileWriter(FileDescriptor fd);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch11-REFSECT1-AUTOID.157">Constructors</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch11-REFSECT2-AUTOID.181">FileWriter</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch11-REFSECT3-AUTOID.224">public FileWriter(String fileName) throws IOException</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>fileName</tt><br>
<DD>

<P CLASS=para>
The pathname of 
the file to use as output. </DL>
<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>FileNotFoundException</tt><br>
<DD>

<P CLASS=para>
If the named file cannot be found.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>SecurityException</tt><br>
<DD>

<P CLASS=para>
If the application does not have permission to write to the named file. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>FileWriter</tt> 
that sends its output to the file named by the specified <tt CLASS=literal>String</tt>. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch11-REFSECT3-AUTOID.225"><DIV CLASS=screen> <P> <PRE> public FileWriter(String fileName, boolean append) throws IOException </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>fileName</tt><br>
<DD>

<P CLASS=para>
The pathname of the file to use as output.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>append</tt><br>
<DD>

<P CLASS=para>
Specifies whether or not data is appended to the output stream. </DL>
<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>FileNotFoundException</tt><br>
<DD>

<P CLASS=para>
If the named file cannot be found.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>SecurityException</tt><br>
<DD>

<P CLASS=para>
If the application does not have permission to write to the named file. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>FileWriter</tt> 
that sends its output to the named file. If <tt CLASS=literal>append</tt> 
is <tt CLASS=literal>true</tt>, the stream is positioned 
at the end of the file, and data is appended to the end of the file. Otherwise, 
if <tt CLASS=literal>append</tt> is <tt CLASS=literal>false</tt>, 
the stream is positioned at the beginning of the file, and any previous 
data is overwritten. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch11-REFSECT3-AUTOID.226">public FileWriter(File file) throws IOException</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>file</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>File</tt> 
to use as output. </DL>
<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>FileNotFoundException</tt><br>
<DD>

<P CLASS=para>
If the named file cannot be found.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>SecurityException</tt><br>
<DD>

<P CLASS=para>
If the application does not have permission to write to the named file. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>FileWriter</tt> 
that sends its output to the file represented by the specified <tt CLASS=literal>File</tt> 
object. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch11-REFSECT3-AUTOID.227">public FileWriter(FileDescriptor fdObj)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>fdObj</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>FileDescriptor </tt>of the file to use as output. </DL>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>SecurityException</tt><br>
<DD>

<P CLASS=para>
If the application does not have permission to write to the specified file.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>NullPointerException</tt><br>
<DD>

<P CLASS=para>
If <tt CLASS=literal>FileDescriptor</tt> is <tt CLASS=literal>null</tt>. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>FileWriter</tt> 
that sends its output to the file identified by the given <tt CLASS=literal>FileDescriptor</tt>. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch11-REFSECT1-AUTOID.158">Inherited Methods</A></h2>

<DIV CLASS=informaltable>
<P>
<TABLE CLASS=INFORMALTABLE>
<TR CLASS=row>
<TH ALIGN="LEFT">

<P CLASS=para>
Method</TH>
<TH ALIGN="LEFT">

<P CLASS=para>
Inherited From</TH>
<TH ALIGN="LEFT">

<P CLASS=para>
Method</TH>
<TH ALIGN="LEFT">

<P CLASS=para>
Inherited From</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>clone()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>close()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>OutputStreamWriter</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>equals(Object)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>finalize()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>flush()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>OutputStreamWriter</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>getClass()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>getEncoding()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>OutputStreamWriter</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>hashCode()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>notify()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>notifyAll()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>toString()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait(long)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait(long, int)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>write(int)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>OutputStreamWriter</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>write(char[])</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Writer</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>write(char[], int, int)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>OutputStreamWriter</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>write(String)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Writer</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>write(String, int, int)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>OutputStreamWriter</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
</TABLE>
<P>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch11-REFSECT1-AUTOID.159">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>BufferedWriter</tt>, 
<tt CLASS=literal>DataOutputStream</tt>, 
<tt CLASS=literal>File</tt>, 
<tt CLASS=literal>FileDescriptor</tt>, 
<tt CLASS=literal>FileNotFoundException</tt>, 
<tt CLASS=literal>FileOutputStream</tt>, 
<tt CLASS=literal>IOException</tt>, 
<tt CLASS=literal>NullPointerException</tt>, 
<tt CLASS=literal>OutputStreamWriter</tt>, 
<tt CLASS=literal>SecurityException</tt>, 
<tt CLASS=literal>Writer</tt> 

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch11_22.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch11_24.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>FileReader</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>FilterInputStream</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
